	

		var year = null;
		var month = null;
		var lastMonthTotalDay = null;
		var currMonthTotalDay = null;
		var weekNumOfCurrMonth = null;
		
		//获取月份对应的天数
		function getMonthTotalDay(year,month){
			var arr = [31,28,31,30,31,30,31,31,30,31,30,31];
			if(month == 2){
				if((year%400==0)||(year%4==0&&year%100!=0)){
				//闰年
				return 29;
				}else{
					//平年
					return arr[month-1];
				}
			}
			return arr[month-1];
		}
		//console.log(getMonthTotalDay(400,2));//测试
		
		//获取日历数据
		function getDatepickerData(year,month){
			//存放数据的数组
			var dateArr = [];
			//设置年份和月份默认值
			//如果没有选择，则使用默认年份，如果选择，则使用选择的年份
			var currYear = !year ? new Date().getFullYear() : year;
			//设置默认月份，同上
			var currMonth = !month ? new Date().getMonth()+1 : month;
			//获取当前月的第一天是星期几
			weekNumOfCurrMonth = new Date(currYear+"-"+currMonth+"-1").getDay();
			weekNumOfCurrMonth = (weekNumOfCurrMonth == 0) ? 7 : weekNumOfCurrMonth;
			//console.log(weekNumOfCurrMonth);//测试
			//获取上个月总共有多少天，要考虑边界，month=1
				var lastMonth = null;
				var lastYear = null;
				if(currMonth==1){
					lastMonth = 12;
					lastYear = currYear -1;
				}else{
					lastMonth = currMonth-1;
					lastYear = currYear;
				}
				lastMonthTotalDay = getMonthTotalDay(lastYear,lastMonth);
				//console.log(lastMonthTotalDay);//测试
				
				//获取当前月有多少天
				currMonthTotalDay = getMonthTotalDay(currYear,currMonth);
				//上个月的日期数据
				for(var i=0;i<weekNumOfCurrMonth;i++){
					dateArr.push(lastMonthTotalDay - weekNumOfCurrMonth + i+1);
				}
				//当前月份的日期
				for(var i=0;i<currMonthTotalDay;i++){
					dateArr.push(i+1);
				}
				//下个月的日期
				for (var i=0;i<(42-weekNumOfCurrMonth-currMonthTotalDay);i++){
					dateArr.push(i+1);
				}
				return dateArr;
				}
		var dateData = getDatepickerData();
		//console.log(dateData);//测试打印
		
		//渲染函数（将数放入表格）
		function render(year,month){
			//获取数据
			var dateData = getDatepickerData(year,month);
			var tabHtml='<tr>'
			+'<th>日</th>'
			+'<th>一</th>'
			+'<th>二</th>'
			+'<th>三</th>'
			+'<th>四</th>'
			+'<th>五</th>'
			+'<th>六</th>'
			+'</tr>';
			//i为行号
			for(var i=0;i<6;i++){
				tabHtml += '<tr>';
				//j代表列号
				var date = new Date();
				var day = date.getDate();
				var nowMonth = date.getMonth()+1;
				for(var j=0;j<7;j++){
					//判断如果不是本月的日期则为td增加一个class用于将字体变为灰色。
					if((lastMonthTotalDay - weekNumOfCurrMonth + (i*7+j)+1)==(dateData[i*7+j])
					||(i*7+j)>=(weekNumOfCurrMonth+currMonthTotalDay)){
						tabHtml += '<td class="notthismonth">'+ dateData[i*7+j] +'</td>';
					}else if(dateData[i*7+j]==day&&month==nowMonth){
						tabHtml += '<td class="today">'+ dateData[i*7+j] +'</td>';
					}else{
						tabHtml += '<td>'+ dateData[i*7+j] +'</td>';
					}
				}
				tabHtml += '</tr>';
			}
			//var tabElem = document.getElementsByTagName("table")[0];
			var tabElem = document.getElementById("CalendarTable");
			var spElem = document.getElementById("tabspan");
			spElem.innerHTML = year+'年'+month+'月';
			tabElem.innerHTML = tabHtml;
		}
		//初始化
		function init(){
			year = new Date().getFullYear();
			month = new Date().getMonth()+1;
			render(year,month);
			//事件绑定
			var datepickerHead = document.getElementsByClassName("xyd-datepicker-head")[0];
			datepickerHead.onclick = function(e){
				if(e.target.nodeName=="A"){
					var direction = e.target.getAttribute("data-direction");
					if(direction == 'prev'){
						if(month==1){
							year--;
							month = 12;
						}else{
							month--;
						}
					}else if(direction == 'next'){
							if(month == 12){
								year++;
								month = 1;
							}else{
								month++;
							}
						}
					render(year,month);
				}
			}
		}
		init();
